mount command
mount
- mount a filesystem
Usage: mount [options] [device] [mount_point]
device
: The filesystem to mount (e.g.,/dev/sdb1
, an ISO file).mount_point
: The directory where the filesystem will be accessible (e.g.,/mnt
).options
: Flags to modify behavior or specify mount settings.
Common Options
Option | Description |
---|---|
-t | Specify filesystem type |
-o | Set mount options |
-a | Mount all filesystems in /etc/fstab |
-r | Mount read-only (same as -o ro ) |
-w | Mount read-write (same as -o rw ) |
-o loop | Mount a file as a loop device |
Examples
-
Listing Mounted Filesystems
Run
mount
without arguments to see all currently mounted filesystems.mount
- Output (partial):
/dev/sda1 on / type ext4 (rw,relatime)
/dev/sdb1 on /mnt/data type ntfs (rw,nosuid,nodev) - Explanation:
/dev/sda1
: Device./
: Mount point.ext4
: Filesystem type.(rw,relatime)
: Mount options (read-write, relative time).
- Output (partial):
-
Mounting a Device
Mount a device to a directory (create the directory first if needed).
sudo mkdir /mnt/usb
sudo mount /dev/sdb1 /mnt/usb- Mounts the partition
/dev/sdb1
(e.g., a USB drive) to/mnt/usb
. - Access files with
ls /mnt/usb
.
Check:
mount | grep /mnt/usb
- Confirms it’s mounted.
- Mounts the partition
-
Specifying Filesystem Type
Use
-t
to specify the filesystem type if it’s not auto-detected.sudo mount -t ntfs /dev/sdb1 /mnt/usb
- Mounts
/dev/sdb1
as an NTFS filesystem.
Common types:
ext4
,ntfs
,vfat
(FAT32),iso9660
(CD/DVD). - Mounts
-
Mounting with Options
Use
-o
to set mount options (e.g., read-only, user permissions).Example (Read-Only):
sudo mount -o ro /dev/sdb1 /mnt/usb
- Mounts as read-only (
ro
).
Example (User Access):
sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/usb
- Allows a specific user (UID 1000) to access it.
Common options:
rw
: Read-write.ro
: Read-only.nosuid
: Block setuid binaries.remount
: Change options on an existing mount.
- Mounts as read-only (
-
Mounting an ISO File
Mount an ISO image as a loop device.
sudo mkdir /mnt/iso
sudo mount -o loop diskimage.iso /mnt/iso- Mounts
diskimage.iso
to/mnt/iso
. - Access contents with
ls /mnt/iso
.
- Mounts
-
Automatic Mounting with
/etc/fstab
Edit
/etc/fstab
for persistent mounts at boot.Add to
/etc/fstab
:/dev/sdb1 /mnt/usb ext4 defaults 0 2
- Then test or apply:
sudo mount -a
- Mounts all
fstab
entries.
- Then test or apply:
-
Remounting
Use
-o remount
to change options without unmounting.sudo mount -o remount,ro /mnt/usb
- Changes
/mnt/usb
to read-only.
- Changes
To get help related to the mount
command use --help
option
$ mount --help
Usage:
mount [-lhV]
mount -a [options]
mount [options] [--source] <source> | [--target] <directory>
mount [options] <source> <directory>
mount <operation> <mountpoint> [<target>]
Mount a filesystem.
Options:
-a, --all mount all filesystems mentioned in fstab
-c, --no-canonicalize don't canonicalize paths
-f, --fake dry run; skip the mount(2) syscall
-F, --fork fork off for each device (use with -a)
-T, --fstab <path> alternative file to /etc/fstab
-i, --internal-only don't call the mount.<type> helpers
-l, --show-labels show also filesystem labels
-n, --no-mtab don't write to /etc/mtab
--options-mode <mode>
what to do with options loaded from fstab
--options-source <source>
mount options source
--options-source-force
force use of options from fstab/mtab
-o, --options <list> comma-separated list of mount options
-O, --test-opts <list> limit the set of filesystems (use with -a)
-r, --read-only mount the filesystem read-only (same as -o ro)
-t, --types <list> limit the set of filesystem types
--source <src> explicitly specifies source (path, label, uuid)
--target <target> explicitly specifies mountpoint
--target-prefix <path>
specifies path used for all mountpoints
-v, --verbose say what is being done
-w, --rw, --read-write mount the filesystem read-write (default)
-N, --namespace <ns> perform mount in another namespace
-h, --help display this help
-V, --version display version
Source:
-L, --label <label> synonym for LABEL=<label>
-U, --uuid <uuid> synonym for UUID=<uuid>
LABEL=<label> specifies device by filesystem label
UUID=<uuid> specifies device by filesystem UUID
PARTLABEL=<label> specifies device by partition label
PARTUUID=<uuid> specifies device by partition UUID
ID=<id> specifies device by udev hardware ID
<device> specifies device by path
<directory> mountpoint for bind mounts (see --bind/rbind)
<file> regular file for loopdev setup
Operations:
-B, --bind mount a subtree somewhere else (same as -o bind)
-M, --move move a subtree to some other place
-R, --rbind mount a subtree and all submounts somewhere else
--make-shared mark a subtree as shared
--make-slave mark a subtree as slave
--make-private mark a subtree as private
--make-unbindable mark a subtree as unbindable
--make-rshared recursively mark a whole subtree as shared
--make-rslave recursively mark a whole subtree as slave
--make-rprivate recursively mark a whole subtree as private
--make-runbindable recursively mark a whole subtree as unbindable
For more details, check the manual with man mount